package com.droidbank.util;

import java.util.Vector;

import android.app.Activity;
import android.app.ProgressDialog;
import android.widget.Toast;

import com.droidbank.model.DataModel;

public class UIUtil {

	public static CharSequence[] convertVectorCS(Vector<?> v)
	{
		CharSequence[] cs = new CharSequence[v.size()];
		v.toArray(cs);
		return cs;
	}
	
	
	public static void showActivitySaveLoad(final Activity activity ,final DataModel dm, String threadId, final boolean save, final boolean sd)
	{
		final ProgressDialog progressDialog = ProgressDialog.show(activity,    
 	              "Please wait...", "Processing data ...", true);
      	
      	//handle the work off the ui thread
  		Runnable   viewOrders = new Runnable(){
  			public void run() {
  				
  				String rval;
  				
  					if(save && !sd)
  						rval  =String.valueOf(dm.saveFile(DataModel.FILE_NAME, true, false));
  					else if(save && sd)
  						rval =String.valueOf(dm.saveFile(DataModel.FILE_NAME_SD, true, true));
  					else if(!save && sd)
  						rval =dm.loadFile(DataModel.FILE_NAME_SD, true);
  					else
  						rval =dm.loadFile(DataModel.FILE_NAME, false);
  						
  					final String val = rval;
  					
  					activity.runOnUiThread(new Runnable()
  	                {
  						public void run() {
  							
  							progressDialog.dismiss();
  							Toast.makeText(activity, (save?"Saved: ":"Loaded: ") + (sd?" SD ":"") +val, 
  			            			Toast.LENGTH_LONG).show();
  						}
  	                	
  	                });
  	            }
  		};
  		
  		
  		new Thread(null, viewOrders, threadId).start();
	}
	
}
